/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.example.netcracker.model;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;
import ru.example.netcracker.model.entity.Notification;
import ru.example.netcracker.model.entity.TaskGroup;

/**
 * @author Nikolay
 */
public class DataBaseProvider implements TaskProvider {

    private static final Logger LOG = Logger.getLogger(DataBaseProvider.class.getName());
    private static final SessionFactory sessionFactory;
    
    static {
        try {
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            LOG.log(Level.SEVERE, "Initial SessionFactory creation failed. {0}", ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
    
    /*public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
    
    public void queryAllTask() {
        Session session = null;
        try {
            session = sessionFactory.openSession();
            Query query = session.createQuery("from Notification");
            //query.setParameter("price", new Float(1000));
            List<Notification>notif = query.list();
            for (Notification n : notif) {
                System.out.println(n.toString());
            }
        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
    }*/

    @Override
    public Scheduler loadTasks() {
        LOG.log(Level.INFO, "loadTasks from db");
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void saveTasks(Scheduler sch) {
        LOG.log(Level.INFO, "saveTasks to db");
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
